<template>
	<div>
		<div style="display: flex;justify-content: space-between;">
			<h2>登分管理-批量登分</h2>
			<button style=" height: 30px;color: #FF0000;" @click="gomarks()">批量修改</button>
		</div>
		<hr />
		<table style="background: #42B983;width: 90vh;" border="1px">
			<tr>
				<th>学生电话</th>
				<th>学生姓名</th>
				<th>班级名称</th>
				<th>课程名称</th>
				<th>分数</th>
			</tr>
			<tr v-for="x in data.marks">
				<th>{{ x.sno }}</th>
				<th>{{ x.user.uname }}</th>
				<th>{{ x.user.clz.clzname }}</th>
				<th>{{ x.course.cname }}</th>
				<th><input style="width: 5vh;" v-model="x.score" /></th>
			</tr>
		</table>
	</div>
</template>

<script setup>
import { ref, reactive, onMounted, computed } from "vue"
import { $get, $postx, $postj, $postf } from '../../ajax/index.js'
import alert from '../../utils/doalert.js'
// import router from '../../../router/index.js'
import { useRoute } from 'vue-router'
const route = useRoute()
const data = reactive({
	marks: [],
	arr: []
})
onMounted(() => {//获取数据,打印数据
	var a = route.query.clzno
	var b = route.query.cno
	console.log(a + b)
	let c = { clzno: a, cno: b }
	$postx("/api/fore/tea/findMark", c).then((reap) => {
		data.marks = reap.data.data
		console.log(reap.data.data)
		for (var i = 0; i < data.marks.length; i++) {
			data.marks[i].oldscore = data.marks[i].score
		}
	})

})
function gomarks() {
	data.arr = []
	for (var i = 0; i < data.marks.length; i++) {
		if (data.marks[i].oldscore != data.marks[i].score) {
			data.marks[i].tpost = new Date()
			data.arr.push(data.marks[i])
		}
	}
	console.log(data.arr)
	$postj("api/fore/tea/addMark", data.arr).then((resp) => {
		alert(resp.data.msg)
	})
}
</script>